var root = {
  val: 1,
  left: {
    val: 2,
    left: {
      val: 4
    },
    right: {
      val: 3
    }    
  },
  right: {
    val: 2,
    left: {
      val: 3
    },
    right: {
      val: 4
    }
  }
}

var isSymmetric = function(root) { // 检查二叉树是否对称的迭代解法
  if (root == null) return true;
  var queue = [];
  queue.push(root.left);
  queue.push(root.right);
  while(queue.length > 0) {
    var left = queue.shift();
    var right = queue.shift();
    if (left == null && right == null) continue;
    if (left == null || right == null) return false;
    if (left.val != right.val) return false;
    queue.push(left.left);
    queue.push(right.right);
    queue.push(left.right); 
    queue.push(right.left);
  }
  return true;
};

console.log(isSymmetric(root))